package com.emotion.recognition.server.mlp;

import java.util.List;

import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;

/**
 * A layer of perceptrons. Could be used for either hidden or output layer.
 * 
 * @author Minsang
 */
public class PerceptronLayer extends AbstractLayer<Perceptron> {

    private final List<Perceptron> nodes = Lists.newArrayList();

    public static PerceptronLayer createHidden(int numNodes, ActivationFunction f, String name,
            Double bias) {
        return new PerceptronLayer(numNodes, f, name, bias);
    }

    public static PerceptronLayer createOutput(int numNodes, ActivationFunction f, String name) {
        return new PerceptronLayer(numNodes, f, name, null);
    }

    private PerceptronLayer(int numNodes, ActivationFunction f, String name, Double bias) {
        super(name, bias);
        Preconditions.checkArgument(numNodes > 0, "Must have at least one node");

        for (int i = 0; i < numNodes; i++) {
            add(Perceptron.create(f));
        }
    }

    @Override
    protected List<Perceptron> getList() {
        return nodes;
    }
}
